<template>
  <el-container class="layout-container-demo" style="height: 100vh">
    <el-aside width="200px">
      <el-scrollbar>
        <h2 style="color: white;text-align: center;">厚溥云课堂</h2>
        <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo" default-active="2"
          text-color="#fff" router>
          <template v-for="(item, index) in menus" :key="item.path">
            <el-sub-menu :index="item.path" v-if="!item.hidden">
              <template #title>
                <el-icon>
                  <component :is="item.meta.icon"></component>
                </el-icon>
                <span>{{ item.meta.title }}</span>
              </template>
              <el-menu-item :index="`${item.path}/${teaitem.path}`" v-for="(teaitem, index) in item.children"
                :key="item.path + teaitem.path">{{ teaitem.meta.title }}</el-menu-item>
            </el-sub-menu>
          </template>
        </el-menu>
      </el-scrollbar>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 20px">
        <div class="toolbar">
          <el-dropdown>
            <el-icon style="margin-right: 8px; margin-top: 1px;color: white;">
              <setting />
            </el-icon>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item  @click="logout">退出</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <span>{{ userStore.userInfo.userName }}</span>
        </div>
      </el-header>

      <el-main>
        <el-card>
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <template v-for="(item, index) in route.matched" :key="index">
              <el-breadcrumb-item v-if="item.path !== '/' && item.path !== '/home'">
                <router-link :to="item.path">{{ item.meta.title }}</router-link>
              </el-breadcrumb-item>
            </template>
          </el-breadcrumb>
        </el-card>
        <!-- 主内容显示区域 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useUserInfo } from "../stote"
import { ElMessage, ElMessageBox } from 'element-plus'
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'

const route = useRoute()
const router = useRouter()
const userStore = useUserInfo()
console.log(route);
console.log(router);

const menus = router.options.routes
console.log(menus);
//点击退出
const logout=()=>{
    ElMessageBox.confirm(
    '您确定要退出吗?',
    '系统提示',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      // ElMessage({
      //   type: 'success',
      //   message: 'Delete completed',
      // })

      //清除用户token信息
      localStorage.removeItem('member_token')
      //跳转至登录页面
        router.push('/login')
    })
    .catch(() => {
     
    })
  }

</script>

<style scoped>
.layout-container-demo .el-header {
  position: relative;
  background-color: #545c64;
  color: white;
}

.layout-container-demo .el-aside {
  color: var(--el-text-color-primary);
  background: #545c64;
}

.layout-container-demo .el-menu {
  border-right: none;
}

.layout-container-demo .el-main {
  padding: 0;
}

.layout-container-demo .toolbar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  right: 20px;
}
</style>
